<?php
/**

 //  The DoYouHaoBaby PHP FrameWork - ajax
 //  +---------------------------------------------------------------------
 //
 //  “Copyright”
 //  +---------------------------------------------------------------------
 //	 | (C) 2010 - 2011 http://doyouhaobaby.net All rights reserved.
 //	 | This is not a free software, use is subject to license terms
 //  +---------------------------------------------------------------------
 //
 //  “About This File”
 //  +---------------------------------------------------------------------
 //	 | ajax Index控制器
 //  +---------------------------------------------------------------------

*/

!defined('DYHB_PATH') && exit;

class IndexController extends Controller{


	/**
	 * 首页 < 默认访问 >
	 *
	 * @access public
	 * @return void
	 */
    public function index(){

	    // 对象
        $arrObjectList = FormModel::F()
			     ->top( 6 )
			     ->order( 'form_id DESC' )
			     ->query();
		$this->assign( 'arrObjectList',$arrObjectList );

		$this->display( );

    }

	public function insert(){

        // 创建模型
       $oModel = new FormModel();

       // 保存数据
       $oModel->save( );

       // 开始查找错误
       if(  !$oModel->isError( ) ) {

            $arrValue = $oModel->toArray();
            $arrValue['create_date']     =   date('Y-m-d H:i:s',$arrValue['create_date'] ); 
            $this->A( $arrValue,'表单数据保存成功！',1 ); 
        }

        else{

        	$this->E(  $oModel->getErrorMessage( ) );
        }

	}

	/** 
	 * 检查标题是否可用
	 */
    public function check_title( ) { 

		$sTitle= Safe::getGpc( 'title','G' );

        if( !empty( $sTitle ) ) { 

            $arrResult = FormModel::F()->getByform_title( $sTitle )->toArray();

            if( !empty( $arrResult['form_id'] ) ) { 

                $this->E('标题已经存在'); 
            }
			
			else{ 

                $this->S( '标题可以使用!' ); 
            } 
        }
		
		else{ 

            $this->E( '标题必须' ); 
        } 
    } 

}
